package com.example.chasshelper.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class AppSQLiteHelper extends SQLiteOpenHelper {
    public AppSQLiteHelper(Context context) {
        //创建数据库
        super(context, "db_phone.txt", null, 1);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        //创建表
        //教师表TEACHER：编号（id）、账号（userAccount）、手机号（phone）、密码（userPassword）、身份（identity）
        String string = "create table teacher(t_id Integer primary key autoincrement,t_account varchar(20),t_phone varchar(20),t_password varchar(20))";
        db.execSQL(string);
        //学生表
        string = "create table student(s_id Integer primary key autoincrement,s_account varchar(20),s_phone varchar(20),s_password varchar(20))";
        db.execSQL(string);
        //课程表Course
        string = "create table course(c_id Integer primary key autoincrement,name varchar(20),create_time varchar(20),t_id Integer, FOREIGN key(t_id)REFERENCES teacher(t_id))";
        db.execSQL(string);
        //课堂表Classroom
        string = "create table classroom(cr_id Integer primary key autoincrement,name varchar(20),create_time varchar(20),c_id Integer, FOREIGN key(c_id)REFERENCES course(c_id))";
        db.execSQL(string);
        //选课表
        string = "create table sc(sc_id Integer primary key autoincrement,s_id Integer,c_id,Integer, FOREIGN key(c_id)REFERENCES course(c_id), FOREIGN key(s_id)REFERENCES student(s_id))";
        db.execSQL(string);

        //消息表Message

//        db.execSQL(string);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        //修改表

    }
}